﻿<div ms-controller="INFO">
    <div class="control-group">
        <label class="control-label">用户名：</label>
        <div class="controls">
            <input class="input-xlarge input-xfat" type='text' ms-if="modelData.ID==0" data-rules="required|minlength=2|maxlength=50" ms-duplex="modelData.UserName" />
            <label ms-if="modelData.ID!=0">{{modelData.UserName}}</label>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">密码：</label>
        <div class="controls">
            <input class="input-xlarge input-xfat" type='password' ms-duplex="modelData.Password" data-rules="required|minlength=2|maxlength=50"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">用户姓名：</label>
        <div class="controls">
            <input class="input-xlarge input-xfat" type='text' ms-duplex="modelData.UserXM" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">手机号：</label>
        <div class="controls">
            <input class="input-xlarge input-xfat" type='text' ms-duplex="modelData.TelePhone" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            角色：
        </label>
        <div class="controls">

            <table class="sui-table table-bordered" id="authDT">
                <tbody>
                    <tr ms-repeat-el="authData">
                        <td>
                            <label class="checkbox-pretty inline menulvl1" ms-class="checked:el.ID==modelData.Role?'checked':''" ms-attr-lid="el.ID">
                                <input type="radio" name="radio"><span>{{el.RoleName}}</span>
                            </label>

                        </td>
                    </tr>
                </tbody>
            </table>

        </div>

    </div>
</div>

   
<script type="text/javascript">

    

    var tempmodel = avalon.define({
        $id: "INFO",
        authData: [],
        modelData: { "ID": "0", "UserName": "", "Password": "", "UserXM": "", "TelePhone": "","Role":"" },
        inittemp: function (strId) {
            $.getJSON(ComFunJS.APIURL("BASE_GETROLE"), { P1: strId, pagecount: 9999 }, function (r) {
                if (r.error == "") {
                    tempmodel.authData = r.result;

                }
            })

            if (strId) {
                ComFunJS.getJSON("BASE_GETUSERMODEL", { "P1": strId }, function (r) {
                    if (r.error == "") {
                        tempmodel.modelData = r.result;


                    }

                })

            } else {
                ComFunJS.initForm();
            }

        },
        SaveData: function (dom, formtype, status) {
            var selAuth = "";
            $("#authDT").find("label.checked").each(function (index, item) {
                if (selAuth) {
                    selAuth += "," + $(item).attr("lid");
                } else {
                    selAuth = $(item).attr("lid");
                }
            })

            tempmodel.modelData.Role = selAuth;

            ComFunJS.postJSON("BASE_ADDUSER", { P1: JSON.stringify(tempmodel.modelData.$model) }, function (r) {
                if (r.error == "") {
                    top.ComFunJS.winShowMsg("操作成功");

                    top.ComFunJS.close();

                } else {
                    top.ComFunJS.winShowAlert(r.error);
                }
            })
        }


    })

</script>

